<include file="Public/min-header"/>
<div class="wrapper">
    <include file="Public/breadcrumb"/>
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><i class="fa fa-list"></i> 秒杀商品编辑</h3>
                    </div>
                    <div class="panel-body">
                        <div class="navbar navbar-default">
                            <form class="navbar-form form-inline" action="" method="post">
                                <div class="form-group pull-left">
                                    <a href="{:U('Miaosha/add_msgoods')}" class="btn btn-primary pull-right"><i
                                            class="fa fa-plus"></i> 添加秒杀商品</a>
                                </div>
                            </form>
                            <div class="pull-right" style="margin-right: 10px">
                                <a href="javascript:history.go(-1)" data-toggle="tooltip" title=""
                                   class="btn btn-default"
                                   data-original-title="返回"><i class="fa fa-reply"></i></a>
                            </div>
                        </div>
                        <div id="ajax_return">
                            <div class="table-responsive">
                                <table class="table table-bordered table-hover">
                                    <thead>
                                    <tr>
                                        <td style="width: 1px;" class="text-center">
                                            <input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);">
                                        </td>
                                        <td class="text-center">商品ID</td>
                                        <td class="text-center">商品名称</td>
                                        <td class="text-center">价格</td>
                                        <td class="text-center">库存量</td>
                                        <td class="text-center">秒杀价</td>
                                        <td class="text-center">参与数量</td>
                                        <td class="text-center">操作</td>
                                    </tr>
                                    </thead>
                                    <tbody>
                                        <volist name="list" id="list">
                                            <tr>
                                                <td class="text-center">
                                                    <input type="checkbox" name="selected[]" value="{$list['goods_id']}">
                                                </td>
                                                <td class="text-center">{$list['goods_id']}</td>
                                                <td class="text-left">{$list['attr']['goods_name']}</td>
                                                <td class="text-center">{$list['attr']['shop_price']}</td>
                                                <td class="text-center">{$list['attr']['store_count']}</td>
                                                <td class="text-center">
                                                    <input  type="numberDecimal"
                                                            name="ms_price"
                                                            ids = "{$list['goods_id']}"
                                                           class="form-control form-control-sm check-goods-data"
                                                            value="{$list['ms_price']==0?$list['attr']['shop_price']:$list['ms_price']}"
                                                           step="0.01" min="0.01"
                                                           max="{$list['ms_price']==0?$list['attr']['shop_price']:$list['ms_price']}"
                                                           style = "width:100px;"
                                                           >
                                                </td>
                                                <td class="text-center">
                                                    <input type="number" name="ms_num" ids = "{$list['goods_id']}"
                                                           class="form-control form-control-sm check-goods-data"
                                                           value="{$list['ms_num']==0?$list['attr']['store_count']:$list['ms_num']}"
                                                           step="1" min="1"
                                                           max="{$list['ms_num']==0?$list['attr']['store_count']:$list['ms_num']}"
                                                           style = "width:100px;"
                                                    />
                                                </td>
                                                <td class="text-center">
                                                    <a href="{:U('Miaosha/info_miaosha_goods',array('goods_id'=>$list['goods_id']))}" href="javascript:;" data-toggle="tooltip"
                                                       title="" class="btn btn-primary" data-original-title="管理"><i
                                                            class="fa fa-pencil"></i></a>
                                                    <a data-url="{:U('Miaosha/del_ms_goods',array('goods_id'=>$list['goods_id']))}"
                                                       onclick="delfun(this)" href="javascript:;" data-toggle="tooltip"
                                                       title="" class="btn btn-danger" data-original-title="删除"><i
                                                            class="fa fa-trash-o"></i></a>

                                                </td>
                                            </tr>
                                        </volist>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-6 text-left"></div>
                            <div class="col-sm-6 text-right">{$page}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>        <!-- /.row -->
    </section>
    <!-- /.content -->
</div>
<script>

    /**
     * 秒杀价
     */
    $('input[name="ms_price"]').blur(function () {
        var ms_price = $(this).val()
        var id = $(this).attr('ids');
        // ms_price = floatval(ms_price);
        // console.log(id);
        // console.log(typeof(ms_price));
        $.post('{:U("Miaosha/ajax_goodsprice")}',{goods_id:id,ms_price:ms_price,},function (e) {
            console.log(e);
            if(e.status){
                layer.alert(e.msg, {icon: 1});

            }else{
                layer.alert(e.msg, {icon: 2});
            }
        })
    });
    /**
     * 秒杀数量
     */
    $('input[name="ms_num"]').blur(function () {
        var ms_num =parseInt($(this).val())
        var id = $(this).attr('ids');
        // console.log(typeof(ms_num));
        $.post('{:U("Miaosha/ajax_goodsnum")}',{goods_id:id,ms_num:ms_num,},function (e) {
            console.log(e);
            if(e.status){
                layer.alert(e.msg, {icon: 1});
            }else{
                layer.alert(e.msg, {icon: 2});
            }
        })
    })

    function delfun(obj) {
        if (confirm('确认删除')) {
            $.ajax({
                type: 'post',
                url: $(obj).attr('data-url'),
                dataType: 'json',
                success: function (data) {
                    console.log(data);
                    if (data) {
                        $(obj).parent().parent().remove();
                    } else {
                        layer.alert('删除失败', {icon: 2});  //alert('删除失败');
                    }
                }
            })
        }
        return false;
    }
</script>
</body>
</html>